<?php
class Admin_Acl_AdminUser_Update_Action extends NICED_Action 
{       
	public function execute() 
	{
        $this->forward("admin.index");

		$controller = $this->getController();
		$request    = $controller->getRequest();			
        $user_id    = $request->loadParam("user_id", NULL, "posint");
        $password   = $request->loadParam("password", NULL, "safe");
        $role_ids   = $request->loadParam("role_ids", NULL);
        $act  = $request->loadParam("act", NULL, "safe");

        //if not have id ,load from uri
        if (!$user_id)
        {
            $user_id = $request->loadArg(0, "user_id", 0, "posint");
        }

        if (!$user_id)
        {
            throw new Exception("please assign user id");
        }

		$model = $controller->getModel('Admin.Acl.AdminUser.Index');
        $model->getByUserId($user_id);

        //if no act param, show create page
        if (!$act)
        {
            return self::SUCCESS;
        }

		try
		{
            $model->update($user_id, $password, $role_ids);
		}
		catch (Exception $e)
		{
			$controller->handleException($e);
			return self::SUCCESS;
		}

		return self::SUCCESS;
	}

}//end class
